package leecode;

/**
 * @author csp 2021-04-29
 */
public class Question14 {
    public String longestCommonPrefix(String[] strs) {
        String prefix = strs[0];
        for (int i = 1; i < strs.length; i++) {
            String currentStr = strs[i];
            int len = Math.min(currentStr.length(), prefix.length());
            int end = len;
            if (prefix.length() == 0) {
                return prefix;
            }
            for (int j = 0; j < len; j++) {
                if (currentStr.charAt(j) != prefix.charAt(j)) {
                    end = j;
                    break;
                }
            }
            if (end == 0) {
            }
            prefix = prefix.substring(0, end);
        }
        return prefix;
    }

    public static void main(String[] args) {
        Question14 question14 = new Question14();
        final String s = question14.longestCommonPrefix(new String[]{"ab", "a"});
        System.out.println(s);
    }
}
